/*
 * RTSAI - Real-Time Strategy engine for AI research
 * Copyright(C) 2006 DIMAp-UFRN, licensed under LGPL
 *
 * Message implementation
 */

#include "Message.h"
#include "Log.h"

// --- MessageReceiver methods ------------------------------------------------
/*! Add a message in the mailbox
 *  @param msg The message that will be added
 */
void ConcreteMessageReceiver :: add_message ( Message *msg )
{
    mbox.push_back ( msg );
}


/*! Transform the mailbox in message array. Returns the number of
 *  messages in the mailbox.
 *  @param msg_array The message array
 */
int ConcreteMessageReceiver :: get_messages ( Message *msg_array[] )
{
    msg_array = &mbox[0];
    return mbox.size();
}


/*! Removes all messages in the mailbox
 */
void ConcreteMessageReceiver :: clear_messages ( )
{
    mbox.clear ( );
}


/*! Returns the number of messages currently in mailbox
 */
int ConcreteMessageReceiver :: get_num_messages ( )
{
    return mbox.size();
}


// --- Message methods --------------------------------------------------------
int Message::unique_id = 0;  // id for new conversations


/*! Constructor 1
 */
Message::Message (  Unit *msg_sender,
                    MessageReceiver *msg_receiver,
                    Performative perf = NONE,
                    string cnt = "") :
        conversation_id ( ++unique_id ),
        sender ( msg_sender ),
        receiver ( msg_receiver ),
        performative ( perf ),
        content ( cnt )
{
    receiver -> add_message ( this );
}

/*! Constructor 2
 */
Message::Message (  int conv_id,
                    Unit *msg_sender,
                    MessageReceiver *msg_receiver,
                    Performative perf = NONE,
                    string cnt = "") :
        conversation_id ( conv_id ),
        sender ( msg_sender ),
        receiver ( msg_receiver ),
        performative ( perf ),
        content ( cnt )
{
    receiver -> add_message ( this );
}

Message::~Message()
{
    //dtor
}
